package logic

import (
	"cart/cartrpc/cartrpcclient"
	"context"

	"cart/api/internal/svc"
	"cart/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddLogic {
	return &CartAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CartAddLogic) CartAdd(req *types.CartAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	cartAdd, err := l.svcCtx.CartRpc.CartAdd(l.ctx, &cartrpcclient.CartAddRequest{
		UserId: req.UserId,
		ShopId: req.ShopId,
		Num:    req.Num,
	})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    500,
			Code:    nil,
		}, nil
	}
	return &types.Response{
		Message: "购物车添加成功",
		Data:    200,
		Code:    cartAdd,
	}, nil
}
